using System;
using System.Runtime.Serialization;
using System.Text;

namespace VXCompany.SilverlightLogging.Services.ServiceContracts
{
	[DataContract]
	public class ExceptionMessage
	{
		#region Properties

		/// <summary>
		/// Gets or sets the client's ip address.
		/// </summary>
		[DataMember(IsRequired = true)]
		public Guid ExceptionMessageID
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets DateTime of error, measured at the client.
		/// </summary>
		[DataMember]
		public DateTime DateTime { get; set; }

		/// <summary>
		/// Gets or sets the client's ip address.
		/// </summary>
		[DataMember]
		public string ClientAddress
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the client application name.
		/// </summary>
		[DataMember(IsRequired = true)]
		public string ClientApplication
		{
			get;
			set;
		}

		/// <summary>
		/// Gets the System.Exception instance that caused the current exception.		
		/// </summary>		
		[DataMember]
		public ExceptionMessage InnerException
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the severity level
		/// </summary>
		[DataMember]
		public ErrorLevel Level
		{
			get;
			set;
		}

		/// <summary>
		/// Gets a message that describes the current exception.
		/// </summary>
		[DataMember]
		public string Message
		{
			get;
			set;
		}

		/// <summary>
		/// Gets or sets the authenticated user's ID.
		/// </summary>
		[DataMember]
		public string UserID
		{
			get;
			set;
		}

		#endregion Properties

		/// <summary>
		/// Returns the Exception object as a string.
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();
			sb.AppendFormat("ExceptionMessageID: {0}", this.ExceptionMessageID);
			sb.AppendFormat("DateTime: {0}", this.DateTime);
			sb.AppendFormat("ClientAddress: {0}", this.ClientAddress);
			sb.AppendFormat("ClientApplication: {0}", this.ClientApplication);

			sb.AppendFormat("Level: {0}", this.Level);
			sb.AppendFormat("Message: {0}", this.Message);

			sb.AppendFormat("UserID: {0}", this.UserID);


			if (this.InnerException != null)
			{
				sb.Append("InnerException");
				try
				{
					sb.Append(this.InnerException.ToString());
				}
				catch { }
			}

			return sb.ToString();
		}
	}
}
